package org.rendao.auth.data;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinTable;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

@Entity
@Table(name = "user")
public class UserDetailDO {

	private String id;
	
	private String username;
	
	private String displayName;
	
	private String password;
	
	private String isDeleted;

	//Cascade
	private Set<UserRoleDO> roles = new HashSet<UserRoleDO>(0);
		
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column(name = "id", nullable = false)
	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	@Column(name="username", nullable = false)
	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	@Column(name="displayname", nullable = false)
	public String getDisplayName() {
		return displayName;
	}

	public void setDisplayName(String displayName) {
		this.displayName = displayName;
	}

	@Column(name="password", nullable = false)
	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	@Column(name="is_deleted", nullable = false)
	public String getIsDeleted() {
		return isDeleted;
	}

	public void setIsDeleted(String isDeleted) {
		this.isDeleted = isDeleted;
	}
	
	@ManyToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
	@JoinTable(name = "user_role", 
		joinColumns = { 
			@JoinColumn(name = "user_id", nullable = false, updatable = false) }, 
		inverseJoinColumns = { 
			@JoinColumn(name = "role_id", nullable = false, updatable = false) })
	public Set<UserRoleDO> getRoles() {
		return this.roles;
	}
 
	public void setRoles(Set<UserRoleDO> roles) {
		this.roles = roles;
	}
}
